package com.poizon.api;

import com.poizon.bo.PageBo;
import com.poizon.dto.MomentInsertDto;
import com.poizon.dto.MomentUpdateDto;
import com.poizon.service.intf.RecordMomentService;
import com.poizon.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName RecordMomentController
 * @Author NoCheng
 * @Date 2022/1/3 16:34
 * @Description:TODO 动态相关
 */
@RestController
@CrossOrigin
@RequestMapping("/api/moment/")
@Api(tags = "动态接口")
public class RecordMomentController {
    private final RecordMomentService service;

    public RecordMomentController(RecordMomentService service) {
        this.service = service;
    }

    @ApiOperation("发布动态")
    @PostMapping()
    public R publish(MomentInsertDto dto){
        return service.publish(dto);
    }

    @ApiOperation("删除动态")
    @DeleteMapping("{id}")
    public R del(@PathVariable Long id){
        return service.del(id);
    }

    @ApiOperation("修改动态")
    @PutMapping()
    public R update(MomentUpdateDto dto, @RequestPart MultipartFile cover, @RequestPart MultipartFile... picture){
        return service.update(dto, cover, picture);
    }

    @ApiOperation("通过类型查询动态")
    @PostMapping("type/{momentTypeId}")
    public R getByType(@RequestBody PageBo bo, @PathVariable Long momentTypeId){
        return service.selectByType(bo, momentTypeId);
    }

    @ApiOperation("查询动态")
    @PostMapping("condition")
    public R getByCondition(@RequestBody PageBo bo, String condition){
        return service.selectByCondition(bo, condition);
    }

    @ApiOperation("获取动态详情")
    @GetMapping("{id}")
    public R getById(@PathVariable Long id){
        return service.selectDetails(id);
    }
}
